﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'ReporteEmpleados')
	BEGIN
		DROP  Procedure  ReporteEmpleados
	END

GO

CREATE Procedure ReporteEmpleados

	(
		@idSucursal int,
		@idArea int,
		@empleado nvarchar(50)
		
	)


AS
begin
     
SELECT     dbo.Ubigeo.Departamento, 
           dbo.Ubigeo.Provincia,
           dbo.Ubigeo.Distrito, 
           dbo.Area.Nombre AS 'Area',
           dbo.Cargo.Nombre AS 'Cargo',
           dbo.Empleados.Apellidos+' '+dbo.Empleados.Nombre AS 'Empleado', 
           dbo.Empleados.DNI,
           dbo.Empleados.Direccion AS 'Dirección',
           dbo.Empleados.Telefono,
           dbo.Empleados.Email 
           
FROM       dbo.Area INNER JOIN
           dbo.Cargo ON dbo.Area.IdArea = dbo.Cargo.IdArea INNER JOIN
           dbo.Sucursal ON dbo.Area.IdSucursal = dbo.Sucursal.IdSucursal INNER JOIN
           dbo.Ubigeo ON dbo.Sucursal.IdUbigeo = dbo.Ubigeo.IdUbigeo INNER JOIN
           dbo.Empleados ON dbo.Cargo.IdCargo = dbo.Empleados.IdCargo
           
           where dbo.Sucursal.IdSucursal=@idSucursal AND dbo.Area.IdArea=@idArea AND dbo.Empleados.Apellidos like @empleado+'%'
end
GO


GRANT EXEC ON ReporteEmpleados TO PUBLIC

GO


